home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / tgrind.zip / TGRINDMA.TE < prev    next >
Text File  |  1990-09-18  |  6KB  |  140 lines

  1. % @(#)tgrindmac.tex    1.4 (LBL) 3/30/85
  2. % Macros for TeX "tgrind" (a TeX equivalent of 4bsd "vgrind").
  3. %
  4. %  Copyright (C) 1985 by Van Jacobson, Lawrence Berkeley Laboratory.
  5. %  This program may be freely used and copied but may not be sold
  6. %  without the author's written permission.  This notice must remain
  7. %  in any copy or derivative.
  8. %
  9. %  Please send improvements, bug fixes, comments, etc., to 
  10. %    van@lbl-rtsg.arpa
  11. %    ...ucbvax!lbl-csam!van
  12. %
  13. %  Modifications.
  14. %  --------------
  15. %  10Feb85, vj    Written.
  16. %  23Mar85, rf  Substitute ambx10 for amb10
  17. %  29Mar85, Chris Torek: Use tt font for all characters in strings.
  18. %        Print decent quotes in comments rather than use tt
  19. %        font quotes.  Show filename (to terminal & log file)
  20. %        at start of each new file.
  21. %  30Mar85, vj    Fixed bug in tabbing.
  22.  
  23. \font\sevenrm=amr7            % font for right margin line numbers
  24. \font\twelvebf=ambx10 scaled \magstep1    % font for page headers
  25. \font\forteenrm=amr10 scaled \magstep2    % font for right margin proc names
  26.  
  27. % tfontedpr outputs a "\Head{Hdr text}" if you give it the "-h" flag.
  28. % We remember the text in "\Header" so it can be included in the 
  29. % head line.
  30. \def\Head#1{\def\Header{#1}}
  31. \def\Header{\null}
  32.  
  33. % We get a "\File{Filename},{Last Mod Time},{Last Mod Date}" at the start of
  34. % each new file.  We remember this stuff for inclusion in the page head & foot.
  35. % We reset the page number & current line number to 0 and output a null
  36. % mark to let the output routine know we're starting a new file.
  37. % We set up the \headline & \footline token lists inside the File macro to
  38. % save remembering the filename & mod time with yet other macros.
  39. \def\File#1,#2,#3{\vfill\eject\mark{\empty}
  40. \global\linecount=0\linenext=9\pageno=1\message{#1}
  41. \headline={\twelvebf\Header\hfil
  42. \edef\a{\topmark}\edef\b{\botmark}\edef\c{\firstmark}
  43. \ifx\c\empty\botmark\else
  44. \ifx\a\empty\botmark\else
  45. \ifx\b\empty\topmark\else
  46. \ifx\a\b\topmark\else\topmark--\botmark\fi
  47. \fi\fi\fi(#1)}
  48. \footline={\it{}#2 #3\hfil{}Page \folio{} of #1}}
  49.  
  50. % There's a "\Proc{Proc Name}" at the start of each procedure.  If
  51. % the language definition allows nested procedures (e.g., pascal), there
  52. % will be a "\ProcCont{Proc Name}" at the end of each inner procedure.
  53. % (In this case, "proc name" is the name of the outer procedure.  I.e.,
  54. % ProcCont marks the continuation of "proc name").
  55. \def\Proc#1{\global\def\Procname{#1}\global\setbox\procbox=\hbox{\forteenrm #1}}
  56. \def\ProcCont#1{\global\def\Procname{#1}
  57. \global\setbox\procbox=\hbox{\forteenrm$\ldots$#1}}
  58. \newbox\procbox
  59. \def\Procname{\null}
  60.  
  61. % Each formfeed in the input is replaced by a "\NewPage" macro.  If
  62. % you really want a page break here, define this as "\vfill\eject".
  63. \def\NewPage{\filbreak\bigskip}
  64.  
  65. % Each line of the program text is enclosed by a "\L{...}".  We turn
  66. % each line into an hbox of size hsize.  If we saw a procedure name somewhere
  67. % in the line (i.e., "procbox" is not null), we right justify "procbox"
  68. % on the line.  Every 10 lines we output a small, right justified line number.
  69. \def\L#1{\filbreak\hbox to \hsize{\CF\strut\global\advance\linecount by1
  70. #1\hss\ifvoid\procbox\linebox\else\box\procbox\mark{\Procname}\fi}}
  71.  
  72. \newcount\linecount \linecount=0
  73. \newcount\linenext \linenext=9
  74. \def\linebox{\ifnum\linecount>\linenext\global\advance\linenext by10
  75. \hbox{\sevenrm\the\linecount}\fi}
  76.  
  77.  
  78. % The following weirdness is to deal with tabs.  "Pieces" of a line
  79. % between tabs are output as "\LB{...}".  E.g., a line with a tab at
  80. % column 16 would be output as "\LB{xxx}\Tab{16}\LB{yyy}".  (Actually, to
  81. % reduce the number of characters in the .tex file the \Tab macro
  82. % supplies the 2nd & subsequent \LB's.) We accumulate the LB stuff in an
  83. % hbox.  When we see a Tab, we grab this hbox (using "\lastbox") and turn
  84. % it into a box that extends to the tab position.  We stash this box in
  85. % "\linesofar" & use "\everyhbox" to get \linesofar concatenated onto the
  86. % front of the next piece of the line.  (There must be a better way of
  87. % doing tabs [cf., the Plain.tex tab macros] but I'm not not enough of a
  88. % TeX wizard to come up with it.  Suggestions would be appreciated.)
  89.  
  90. \def\LB{\CF\hbox}
  91. \newbox\linesofar\setbox\linesofar=\null
  92. \everyhbox={\box\linesofar}
  93. \newdimen\TBwid
  94. \def\Tab#1{\setbox\tbox=\lastbox\TBwid=1\wd\tbox\advance\TBwid by 1\ts
  95. \ifdim\TBwid>#1\ts
  96. \setbox\linesofar=\hbox{\box\tbox\space}\else
  97. \setbox\linesofar=\hbox to #1\ts{\box\tbox\hfil}\fi\LB}
  98.  
  99. % A normal space is too thin for code listings.  We make spaces & tabs
  100. % be in "\ts" units (which are the width of a "0" in the current font).
  101. \newdimen\ts
  102. \newbox\tbox
  103. \setbox\tbox=\hbox{0} \ts=1\wd\tbox \setbox\tbox=\hbox{\hskip 1\ts}
  104. \def\space{\hskip 1\ts\relax}
  105.  
  106. % Font changing stuff for keywords, comments & strings.  We put keywords
  107. % in boldface, comments in text-italic & strings in typewriter.  Since
  108. % we're usually changing the font inside of a \LB macro, we remember the
  109. % current font in \CF & stick a \CF at the start of each new box.
  110. % Also, the characters " and ' behave differently in comments than in
  111. % code, and others behave differently in strings than in code.
  112. \newif\ifcomment\newif\ifstring
  113. \let\CF=\rm
  114. \def\K#1{{\bf #1}}    % Keyword
  115. \def\C{\it\global\let\CF=\it\global\commenttrue\relax}    % Comment Start
  116. \def\CE{\rm\global\let\CF=\rm\global\commentfalse\relax}% Comment End
  117. \def\S{\tt\global\let\CF=\tt\global\stringtrue\relax}    % String Start
  118. \def\SE{\rm\global\let\CF=\rm\global\stringfalse\relax}    % String End
  119.  
  120. % Special characters.
  121. \def\{{\ifmmode\lbrace\else\ifstring{\char'173}\else$\lbrace$\fi\fi}
  122. \def\}{\ifmmode\rbrace\else\ifstring{\char'175}\else$\rbrace$\fi\fi}
  123. \def\!{\ifmmode\backslash\else\ifstring{\char'134}\else$\backslash$\fi\fi}
  124. \def\|{\ifmmode|\else\ifstring{\char'174}\else$|$\fi\fi}
  125. \def\<{\ifmmode<\else\ifstring<\else$<$\fi\fi}
  126. \def\>{\ifmmode>\else\ifstring>\else$>$\fi\fi}
  127. \def\/{\ifmmode/\else\ifstring/\else$/$\fi\fi}
  128. \def\-{\ifmmode-\else\ifstring-\else$-$\fi\fi}
  129. \def\_{\ifstring{\char'137}\else\underbar{\ }\fi}
  130. \def\&{{\char'046}}
  131. \def\#{{\char'043}}
  132. \def\%{{\char'045}}
  133. \def\~{{\char'176}}
  134. \def\"{\ifcomment''\else{\tt\char'042}\fi}
  135. \def\'{\ifcomment'\else{\tt\char'047}\fi}
  136. \def\^{{\char'136}}
  137. \def\${{\rm\char'044}}
  138.  
  139. \raggedright\obeyspaces\let =\space%
  140.